package com.zwj.interview.链表;

/**
 * @Author: Zwj
 * @Date: 2022/2/28 14:38
 */
public class 翻转链表前n个节点 {

    /**
     *
     *  1->2->3->4->5
     *  1<-2<-3
     *  对于节点1,2来说，翻转后的关系就是head.next.next=head;
     *  将翻转后
     *  head.next=successor;
     */
    public ListNode reverseN(ListNode head,int n){
        ListNode successor=null;
        if(n==1){
           successor=head.next;
           return head;
        }
        ListNode last=reverseN(head.next,n-1);
        head.next.next=head;
        head.next=successor;
        return last;
    }




}